package cn.edu.nwpu.warehousemanagement.pojo;

import cn.edu.nwpu.warehousemanagement.constantEnum.ReplenishStrategy;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 库存配置
 *
 * @author Loadstar
 * @version 1.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(
        name = "inventory_config",
        uniqueConstraints = @UniqueConstraint(
                columnNames = "product_id",  // 对应外键字段名
                name = "uc_inventory_config_product_id"  // 自定义约束名
        )
)
public class InventoryConfig extends BaseEntity {

    // 商品ID，关联商品表，不可为空
    @OneToOne
    @JoinColumn(name = "product_id", nullable = false, foreignKey = @ForeignKey(name = "fk_InventoryConfig_product"))
    private Product product;

    // 库存下限，默认值为 0
    @Column(name = "min_stock", nullable = false, columnDefinition = "INT DEFAULT 0")
    private Integer minStock;

    // 库存上限，不可为空
    @Column(name = "max_stock", nullable = false)
    private Integer maxStock;

    // 安全库存，默认值为 0
    @Column(name = "safety_stock", columnDefinition = "INT DEFAULT 0")
    private Integer safetyStock;


    // 补货策略，默认值为 'auto'
    @Enumerated(EnumType.STRING)
    @Column(name = "replenish_strategy", length = 20, columnDefinition = "VARCHAR(20) DEFAULT 'AUTO'")
    private ReplenishStrategy replenishStrategy;

    // 最后预警时间
    @Column(name = "last_alert_time")
    private LocalDateTime lastAlertTime;

}
